/*
The MIT License (MIT)

Copyright (c) 2013 Mike Dapiran, Brian May, Richard Pospesel, and Bert Wierenga

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software 
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#pragma once

#include "Hogshead.Input.Enums.h"

#define DIRECTINPUT_VERSION 0x0800
#include <dinput.h>

namespace hhd
{
	class DirectInputManager
	{
	public:
		static void initialize();
		static void finalize();

		/**
		* Updates the current keyboard state and determines if it has changed.
		* @return True if state has changed (keys pressed or released) and False if still the same
		*/
		static bool pollKeyboard();
		/**
		* Updates the current mouse state and determines if it has changed.
			
		*/
		static bool pollMouse(bool confine_to_window);
	private:
		// direct input garbage
		static LPDIRECTINPUT8 _di_object;
		static LPDIRECTINPUTDEVICE8 _keyboard_device;
		static LPDIRECTINPUTDEVICE8 _mouse_device;

		// data used for keyboard
		static char _keyboard_buffer[256];
		static Input::KeyState* _ks_0;
		static Input::KeyState* _ks_1;

		// data used for mizouse
		static DIMOUSESTATE2 _mouse_buffer;
		static int* _mouse_deltas;
		static int* _mouse_positions;
		static Input::ButtonState* _mouse_button_states_0;
		static Input::ButtonState* _mouse_button_states_1;

		static bool _mouse_moved;
		static bool _mouse_buttons_changed;

		static HWND _window_handle;
		friend class DirectInputDirector;
	};
}